/*
 * prints all possible combination of charactes in a string 
 * Could use BIT, see Bit Manipulation/PowerSet.java
 */
class Combination{

	public Combination(){
		
	}

	public static void combine(String str){ // do initialization
		int length = str.length();
		char[] instr = str.toCharArray();
		StringBuilder out = new StringBuilder();
		
		doCombine(instr,out,length,0,0); 
	}
	
	public static void doCombine(char[] instr, StringBuilder out, int length, 
								int level, int start){
		
		for (int i = start; i < length; i++){
			out.append(instr[i]);
			System.out.println(" out="+out.toString());
			
			if( i < length - 1){
				doCombine(instr,out,length,level+1,i+1);
			}
			out.setLength(out.length()-1);
		}
	}
	
	public static void main(String[] args){
		String string = "hufei";
		combine(string);
	}
}
